
#include <BVBoxLayout>
#include <BHBoxLayout>
#include <BChangeEvent>
#include <BPainter>
#include <BStyle>
#include <BFont>
#include <BLabel>

#include "HtmlBox.h"

HtmlBox::HtmlBox(const BString& name) : BWidget(name)
{
	_vlayout = new BVBoxLayout(this);
	_vlayout->setSpacing(3);
	{
		_lineLayout = new BHBoxLayout();
		_vlayout->addLayout(_lineLayout);
	}
}
HtmlBox::~HtmlBox()
{

}

void HtmlBox::addBox(HtmlBox* box)
{
	const BString& name = box->name();
	bool lineFeed = name.size() == 2 && name[0] == 'h' && name[1] >= '1' && name[1] <= '9';
	if (!lineFeed)
		lineFeed = name == "div" || name == "br" || name == 'p';
	if (name == "br")
		box->setWidthStretch(10000.0f);
	if (!lineFeed)
		lineFeed = box->find("div");
	_lineLayout->addWidget(box);
	if (lineFeed)
	{
		_lineLayout = new BHBoxLayout();
		_vlayout->addLayout(_lineLayout);
	}
}
void HtmlBox::addLabel(BLabel* label)
{
	_lineLayout->addWidget(label);
}

void HtmlBox::changeEvent(const BChangeEvent& event)
{
	const BFont* font = this->font();
	this->setMinSize(font->size());
}
void HtmlBox::adjustEvent(const BEvent& event)
{
	BWidget::adjustEvent(event);
}
